package cn.k23.bymain.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @Description: 访问地址http://localhost:8080/doc.html#home
 * @Author: k23
 * @Date: 2022-05-09 14:28
 * @Version: 1.0
 */
    @Configuration
    @EnableOpenApi  //启动器可以不配置
    public class SwaggerConfig {

        @Bean
        public Docket createRestApi(){
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(apiInfo())
                    .enable(true) //配置是否启用Swagger，如果是false，在浏览器将无法访问
                    .select()// 通过.select()方法，去配置扫描接口,RequestHandlerSelectors配置如何扫描接口
                    .apis(RequestHandlerSelectors.basePackage("cn.k23.bymain.controller"))
                    // 配置如何通过path过滤,即这里只扫描请求以/api开头的接口
                    .paths(PathSelectors.ant("/api/**"))
                    .build();
        }

        private ApiInfo apiInfo(){
            return new ApiInfoBuilder()
                    .title("卢本伟的武器库")
                    .description("这是卢本伟的武器库后台接口文档,实时更新，请及时关注接口变化！")
                    .version("v1.0")
                    .contact(new Contact("k23", "http://localhost", "3519973006@qq.com"))
                    .build();
        }
    }

